package com.lixin.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitDirectConfig {

    // 创建direct模式交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(
                "direct_order_exchange", // 交换机名称
                false, // 交换机是否持久化
                true // 是否自动删除交换机
        );
    }

    // 创建短信消息队列
    @Bean
    public Queue directSmsQueue() {
        return new Queue(
                "sms.direct.queue", // 队列名称
                false // 是否持久化
        );
    }

    // 创建微信消息队列
    @Bean
    public Queue directWechatQueue() {
        return new Queue("wechat.direct.queue", false);
    }

    // 创建邮件消息队列
    @Bean
    public Queue directEmailQueue() {
        return new Queue("email.direct.queue", false);
    }

    // 将短信消息队列绑定到交换机
    @Bean
    public Binding directSmsBinding() {
        return BindingBuilder.bind(directSmsQueue()).to(directExchange()).with("sms");
    }

    // 将微信消息队列绑定到交换机
    @Bean
    public Binding directWechatBinding() {
        return BindingBuilder.bind(directWechatQueue()).to(directExchange()).with("wechat");
    }

    // 将邮件消息队列绑定到交换机
    @Bean
    public Binding directEmailBinding() {
        return BindingBuilder.bind(directEmailQueue()).to(directExchange()).with("email");
    }

}
